<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */

include 'dbconnect.php';
include 'includes/functions.php';
include 'includes/clientfunctions.php';
$loginsuccess = false;
$username = trim ($username);
$password = trim ($password);
if (($username AND ($password OR $_SESSION['adminid'])))
{
	unset ($where);
	$where['email'] = $username;
	if (!$_SESSION['adminid'])
	{
		$where['status'] = array ('sqltype' => 'NEQ', 'value' => 'Closed');
	}

	$result = select_query ('tblclients', '', $where);
	$data = mysql_fetch_array ($result);
	$login_uid = $data['id'];
	$login_pwd = $data['password'];
	$language = $data['language'];
	$salt = explode (':', $login_pwd);
	$salt = $salt[1];
	if ($login_uid)
	{
		if ($CONFIG['NOMD5'])
		{
			$check_pwd = decrypt ($login_pwd);
		}
		else
		{
			$password = generateclientpw ($password, $salt);
			$check_pwd = $login_pwd;
		}

		if (($password === $check_pwd OR $_SESSION['adminid']))
		{
			if (!$_SESSION['adminid'])
			{
				$fullhost = gethostbyaddr ($remote_ip);
				update_query ('tblclients', array ('lastlogin' => 'now()', 'ip' => $remote_ip, 'host' => $fullhost), array ('id' => $login_uid));
			}

			$_SESSION['uid'] = $login_uid;
			if ($CONFIG['DisableSessionIPCheck'])
			{
				$haship = '';
			}
			else
			{
				$haship = $remote_ip;
			}

			$_SESSION['upw'] = md5 ($login_uid . $login_pwd . $haship);
			$loginsuccess = true;
			run_hook ('ClientLogin', array ('userid' => $login_uid));
			if ($language)
			{
				$_SESSION['Language'] = $language;
			}

			if ($rememberme)
			{
				setcookie ('WHMCSUID', $_SESSION['uid'], time () + 60 * 60 * 24 * 365);
				setcookie ('WHMCSPW', $_SESSION['upw'], time () + 60 * 60 * 24 * 365);
			}
		}
	}
}

$goto = preg_replace ('/[^0-9a-z-]/i', '', $goto);
if ($goto == 'viewinvoice')
{
	$gotopage = '' . 'viewinvoice.php?id=' . $id;
}
else
{
	if ($goto == 'viewticket')
	{
		$gotopage = '' . 'viewticket.php?tid=' . $tid . '&c=' . $c;
	}
	else
	{
		if ($goto == 'knowledgebase')
		{
			$gotopage = '' . 'knowledgebase.php?action=displayarticle&catid=' . $catid . '&id=' . $id;
		}
		else
		{
			if ($goto == 'order')
			{
				$gotopage = 'order.php?step=checkout';
			}
			else
			{
				if ($goto == 'cart')
				{
					$gotopage = 'cart.php?a=checkout';
				}
				else
				{
					if ($goto == 'supporttickets')
					{
						$gotopage = 'supporttickets.php';
					}
					else
					{
						if ($goto == 'submitticket')
						{
							$gotopage = 'submitticket.php';
						}
						else
						{
							if ($goto == 'affiliates')
							{
								$gotopage = 'affiliates.php';
							}
							else
							{
								if ($goto == 'configuressl')
								{
									$gotopage = '' . 'configuressl.php?cert=' . $cert;
								}
								else
								{
									if ($goto == 'download')
									{
										$gotopage = '' . 'dl.php?type=' . $type . '&id=' . $id;
									}
									else
									{
										if (file_exists (ROOTDIR . '/' . $goto . '.php'))
										{
											$gotopage = $goto . '.php';
										}
										else
										{
											$gotopage = 'clientarea.php';
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

if (!$loginsuccess)
{
	if ((($goto == 'viewinvoice' OR $goto == 'viewticket') OR $goto == 'knowledgebase'))
	{
		$gotopage .= '&incorrect=true';
	}
	else
	{
		$gotopage .= '?incorrect=true';
	}

	if ($goto == 'order')
	{
		$gotopage = 'order.php?step=login&func=incorrect';
	}

	if ($goto == 'cart')
	{
		$gotopage = 'cart.php?a=login&incorrect=true';
	}

	if ($goto == 'configuressl')
	{
		$gotopage = '' . 'configuressl.php?cert=' . $cert . '&incorrect=true';
	}
}

header ('' . 'Location: ' . $gotopage);
exit ();
?>